<template>
  <div class="page app-list">
    <table>
      <thead>
        <tr>
          <th>appid</th>
          <th>应用名称</th>
          <th>应用描述</th>
          <th>创建时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(app, i) in apps" :key="app._id">
          <td>{{ app._id }}</td>
          <td>{{ app.name }}</td>
          <td>{{ app.desc }}</td>
          <td>{{ formatTime(app.create_time) }}</td>
          <td>
            <a href="#" @click.prevent="roleList" :data-index="i">账号管理</a>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import dateTool from '../utils/date_tool'
import utils from '../utils/index'
import store from '../utils/store'

export default {
  name: 'AppList',
  data () {
    return {
      apps: []
    }
  },
  created () {
    phax.get('/account_allocation/app/list').then(res => {
      this.apps = res.apps
    })
  },
  methods: {
    // 格式化时间
    formatTime (datetime) {
      return dateTool.format(datetime, 'yyyy-mm-dd HH:MM:dd')
    },
    // 分配账号
    roleList (e) {
      let app = Number(utils.data(e.target, 'index'))
      app = this.apps[app]
      store.set('app', JSON.stringify({ appid: app._id, name: app.name }))

      this.$router.push('/role_list')
    }
  }
}
</script>

<style lang="stylus">
.app-list
  padding 50px
  overflow auto
</style>
